package com.hnhy.hnhyscms_ws.controller;

import com.hnhy.hnhyscms_ws.entity.Suppliers;
import com.hnhy.hnhyscms_ws.service.ISuppliersSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/suppliers")
public class SuppliersController {
    @Autowired
    private ISuppliersSevice iSuppliersSevice;
    @RequestMapping(value = "/getAllSuppliers",method= RequestMethod.GET)
    public List<Suppliers> getAllSuppliers(){ return iSuppliersSevice.getAllSuppliers(); }
    @RequestMapping(value = "/getBySupplierNo",method = RequestMethod.POST)
    public Suppliers getBySupplierNo(@RequestParam String supplierNo){ return  iSuppliersSevice.getBySupplierNo(supplierNo); }
    @RequestMapping(value = "/deleteSuppliers",method = RequestMethod.POST)
    public void deleteSuppliers(@RequestParam String supplierNo){   iSuppliersSevice.deleteSuppliers(supplierNo); }
    @RequestMapping(value = "/changeBySupplierNo",method = RequestMethod.POST)
    public void changeBySupplierNo(
            @RequestParam String supplierNo,
            @RequestParam String supplierName,
            @RequestParam String linkPerson,
            @RequestParam String linkPhone,
            @RequestParam String linkAddr,
            @RequestParam String invoiceInfo,
            @RequestParam String fax,
            @RequestParam String remarks){
        Suppliers suppliers=new Suppliers();
        suppliers.setSupplierNo(supplierNo);
        suppliers.setSupplierName(supplierName);
        suppliers.setLinkPerson(linkPerson);
        suppliers.setLinkPhone(linkPhone);
        suppliers.setLinkAddr(linkAddr);
        suppliers.setInvoiceInfo(invoiceInfo);
        suppliers.setFax(fax);
        suppliers.setRemarks(remarks);
        iSuppliersSevice.changeBySupplierNo(suppliers);
    }
    @RequestMapping(value = "/changeStatus",method = RequestMethod.POST)
    public void changeStatus(
            @RequestParam String supplierNo,
            @RequestParam Byte status){   iSuppliersSevice.changeStatus(supplierNo,status); }
    @RequestMapping(value = "/addSuppliers",method = RequestMethod.POST)
    public void addSuppliers(
            @RequestParam String supplierName,
            @RequestParam String linkPerson,
            @RequestParam String linkPhone,
            @RequestParam String linkAddr,
            @RequestParam String areaName,
            @RequestParam String invoiceInfo,
            @RequestParam String fax,
            @RequestParam String remarks)
    {
        byte status=1;
        Suppliers suppliers=new Suppliers();
        suppliers.setSupplierName(supplierName);
        suppliers.setLinkPerson(linkPerson);
        suppliers.setLinkPhone(linkPhone);
        suppliers.setLinkAddr(linkAddr);
        suppliers.setAreaName(areaName);
        suppliers.setInvoiceInfo(invoiceInfo);
        suppliers.setFax(fax);
        suppliers.setRemarks(remarks);
        suppliers.setStatus(status);
        suppliers.setSupplierNo("hyS"+"0000"+(iSuppliersSevice.findMaxId().getSid()+1));
        iSuppliersSevice.addSuppliers(suppliers);
        return;
    }
}
